<?php
  require_once 'DB.php';
  include_once("./libraries/db.inc.php");
  include_once("./libraries/authentication.inc.php");
  include_once("./queries/jobQueue.inc.php");
  include_once("./libraries/util.inc.php");
  include_once("./libraries/displayUtils.inc.php");
  include_once("./libraries/recordset.inc.php");

  set_time_limit(0);
  session_start();
  sessionAuthenticate("login.php");

  $dataIndex = "jobQueueList";
  
  $refresh = false;
  $queryType = -1;
  $params = array();
  $status = array();
  $displayPage = 1;
  unset($owner);


  //process the get variables
  foreach ($_GET as $varName => $value) {
	//echo "varName: {$varName}, value: {$value}\n";
	if ($varName == "refresh") {
	  $refresh=$value;
        } elseif ($varName == "qt") {
	   $queryType = $value;
        } elseif (($varName == "waiting" || 
                   $varName == "held" || 
                   $varName == "running" ||
				   $varName == "completed"
                  ) && $value == "true") {
           $status[count($status)] = $varName;
           
        } elseif ($varName == "dP") {
            $displayPage = $value;
        } elseif ($varName == "owner") {
            //echo "AAAAAAAAAAAAAA{$value}";
            if ($_SESSION["administrator"] === true) {
              $owner = urldecode($value);
              //echo $owner;
              //if ($owner == "<b>Total</b>") unset ($owner);
              //echo "$owner";
            }
        } else {
          $params["{$varName}"] = $value;
        } 
  }


  if (count($params)==0 && count($status)==0 && !(isset($owner))) { 
    $params = $_SESSION["{$dataIndex}"]["params"];
    $status = $_SESSION["{$dataIndex}"]["status"];
    $owner = $_SESSION["{$dataIndex}"]["owner"];
  }

  //we need to get the data
  $connection = DB::connect($dsn, $options);
  if (DB::isError($connection)) {
    trigger_error($connection->getMessage(), E_USER_ERROR);
  }

  if (!(isset($owner))) {
    $owner = NULL;
  }
  $rs = jobQueueList($connection, $dataIndex, $params, $status, $owner, $displayPage);
 //echo "called it";

  $connection->disconnect();
 
  $rs->setLinkParams(2, array("schedd","cid","pid"), array(0,1,2), "procInfo.php");

  if ($_SESSION["administrator"] === true) {
    $rs->setLinkParams(7, array("mid"), array(7), "machineInfo.php");
  }
  //$rs->linkFile = "procInfo.php";

  //$rs->simpleSetLinkParams(0, "mid");
  //$rs->linkFile = "machineInfo.php";
  //echo "Size is now: {$rs->recordCount}";
  $rs->printNavigablePage($_SESSION["{$dataIndex}"]["title"],
                          $_SESSION["{$dataIndex}"]["message"],
                          $displayPage,
                          "./jobQueueList.php");

  cdbFinishPage();
?>
